package ace.module.oauth2.server.sdk.core.util;

import java.nio.charset.StandardCharsets;
import java.util.Base64;
import org.springframework.util.Assert;

/**
 * @author caspar
 * @date 2023/2/9 14:54 授权辅助工具
 */
public final class AuthorizationUtils {

  public static String getBasicAuthorization(String username, String password) {
    Assert.notNull(username, "username can't be null ");
    Assert.notNull(password, "password can't be null ");
    byte[] rawAuthorizationBytes = (username + ":" + password).getBytes(StandardCharsets.UTF_8);
    return "Basic " + Base64.getEncoder().encodeToString(rawAuthorizationBytes);
  }
}
